/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package beans;

import core.Course;
import db.dao.CourseDAO;
import javax.annotation.PostConstruct;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * View the description for a selected course.
 *
 * @author Mikael
 */
public class CoursePageBean {
    private Course course;

    @PostConstruct
    public void init(){
        course = new Course();
    }

    public Course getCourse() {
        //Get active login id by getting login session bean
        FacesContext facesCont = FacesContext.getCurrentInstance();
        HttpSession https = (HttpSession)facesCont.getExternalContext().getSession(false);
        ViewChangeBean vcb =
                (ViewChangeBean)https.getAttribute(ViewChangeBean.MANGED_BEAN_NAME);

        Integer courseId = Integer.parseInt(vcb.getParam());

        course = CourseDAO.read(courseId);

        return course;
    }

    public void setCourse(Course course) {
        this.course = course;
    }
}
